package com.tars.txappstart.service.impl;

import com.tars.txappstart.dao.StartDao;
import com.tars.txappstart.entity.PaymentEntity;
import com.tars.txappstart.service.StartService;
import com.tars.txappstart.utils.HttpClientResult;
import com.tars.txappstart.utils.HttpClientUtil;
import com.tars.txtm.annotation.GlobalTransactional;
import com.tars.txtm.trasactional.MyTransactionalManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: Franz 2022/3/14
 */
@Service
public class StartServiceImpl implements StartService {

    @Autowired
    private StartDao dao;

    @GlobalTransactional(isStart = true)
    public void startService(Integer paymeny, Integer order) {
        PaymentEntity entity = new PaymentEntity();
        entity.setPayment(1);
        dao.insert(entity);

        int a = 1/(paymeny - 10);

        try {
            Map<String, String> headers = new HashMap();
            headers.put("txGroupID", MyTransactionalManager.getCurrentTxGroupID());
//            headers.put("transactionCount", MyTransactionManager.getTransactionCount());
            HttpClientResult result = HttpClientUtil.doPost("http://localhost:24002/end/test/"+order, headers,null);
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

        int b = 1/paymeny;
    }
}
